<?php
// +----------------------------------------------------------------------
// | Author: Stupboy King
// +----------------------------------------------------------------------
namespace app\api\controller\driver;
use think\Controller;
use think\Request;
class Base extends \app\api\controller\Base
{
    public function _initialize()
    {
        // Redis缓存
        $this->redis = new \Redis();
        $this->redis->connect('127.0.0.1', 6379);
        $this->dtoken= input('dtoken','');
        $this->requestMethod = true;// Request::instance()->isPost(); 测试期间允许GET方便测试
    }

    public function setRedis($key,$value){
        $data = is_array($value) ? serialize($value) : $value;
        $this->redis->set($key,$data);
    }

    public function getRedis($key){
        $value    = $this->redis->get($key);
        $jsonData = unserialize($value);
        return (null === $jsonData) ? $value : $jsonData;
    }


    /**
     * 成功返回
    */
    public function retSucc($data=array(),$msg='ok',$code=1){
        $info['code'] = $code;
        $info['msg']  = $msg;
        $info         = array_merge($info,$data);
        return json($info);
    }

    /**
     * 失败返回
    */
    public function retError($msg='',$code=0){
        $info['code'] = $code;
        $info['msg']  = $msg;
        return json($info);
    }

}
